/**
 * 
 */
package org.bspv.pharma.web.bean.node.visitor;

import java.util.Map;

import org.bspv.pharma.web.bean.node.Node;

/**
 * @author guillaume
 *
 */
public abstract class AbstractVisitor implements Visitor {

	/* (non-Javadoc)
	 * @see org.bspv.pharma.webapp.bean.node.visitor.Visitor#visit(org.bspv.pharma.webapp.bean.node.Node)
	 */
	public String visit(Node node, Map<String, String> params) {
		StringBuilder sb = new StringBuilder();
		// ouverture
		sb.append("<li>");
		sb.append("<span>");
		sb.append(node.toString());
		sb.append("</span>");
		
		boolean children = false;
		if(node.getChildren() != null && node.getChildren().size()>0) {
			sb.append("<ul name=\"");
			sb.append(node.getName());
			sb.append("\"_children>");
			children = true;
		}
		for (Node child : node.getChildren()) {
			sb.append(VisitorManager.getVisitor(child.getClass()).visit(child, params));
		}
		if(children) {
			sb.append("</ul>");
		}
		// fermeture
		sb.append("</li>");
		return sb.toString();
	}

}
